CREATE TABLE [dbo].[NC]
(
[ID] [numeric] (10, 0) NOT NULL IDENTITY(1, 1),
[ID_TIPO] [numeric] (10, 0) NOT NULL,
[ID_CLIENTE] [numeric] (10, 0) NOT NULL,
[ID_NCF] [numeric] (10, 0) NOT NULL,
[ID_VENDEDOR] [numeric] (10, 0) NOT NULL,
[ID_USUARIO] [numeric] (10, 0) NOT NULL,
[ID_FACTURA] [numeric] (10, 0) NOT NULL,
[NRO_DOCUMENTO] [numeric] (10, 0) NOT NULL CONSTRAINT [DF_NC_NRO_DOCUMENTO] DEFAULT ((0)),
[SEQ_NCF] [numeric] (10, 0) NOT NULL,
[FECHA] [datetime2] NOT NULL CONSTRAINT [DF_NC_FECHA] DEFAULT (getdate()),
[OBSERVACIONES] [varchar] (150) COLLATE SQL_Latin1_General_CP1_CI_AS NULL CONSTRAINT [DF_NC_OBSERVACIONES] DEFAULT (''),
[T_IMPUESTO] [numeric] (10, 2) NOT NULL,
[T_DESCUENTO] [numeric] (10, 2) NOT NULL,
[M_TOTAL] [numeric] (10, 2) NOT NULL,
[M_UTILIZADO] [numeric] (10, 2) NOT NULL,
[ACTIVO] [bit] NOT NULL CONSTRAINT [DF_NC_ACTIVO] DEFAULT ((1)),
[M_PENDIETE] AS (isnull(isnull([M_TOTAL],(0))-isnull([M_UTILIZADO],(0)),(0)))
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[NC] ADD CONSTRAINT [PK_NC] PRIMARY KEY CLUSTERED  ([ID]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_NC] ON [dbo].[NC] ([NRO_DOCUMENTO]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[NC] ADD CONSTRAINT [FK_NC_CLIENTES] FOREIGN KEY ([ID_CLIENTE]) REFERENCES [dbo].[CLIENTES] ([ID])
GO
ALTER TABLE [dbo].[NC] ADD CONSTRAINT [FK_NC_FACTURAS] FOREIGN KEY ([ID_FACTURA]) REFERENCES [dbo].[FACTURAS] ([ID])
GO
ALTER TABLE [dbo].[NC] ADD CONSTRAINT [FK_NC_NCF] FOREIGN KEY ([ID_NCF]) REFERENCES [dbo].[NCF] ([ID])
GO
ALTER TABLE [dbo].[NC] ADD CONSTRAINT [FK_NC_NC_TIPOS] FOREIGN KEY ([ID_TIPO]) REFERENCES [dbo].[NC_TIPOS] ([ID])
GO
ALTER TABLE [dbo].[NC] ADD CONSTRAINT [FK_NC_USUARIOS] FOREIGN KEY ([ID_USUARIO]) REFERENCES [dbo].[USUARIOS] ([ID])
GO
ALTER TABLE [dbo].[NC] ADD CONSTRAINT [FK_NC_VENDEDORES] FOREIGN KEY ([ID_VENDEDOR]) REFERENCES [dbo].[VENDEDORES] ([ID])
GO
